using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Utilities;
using Microsoft.Phone.Tasks;

//game.Components.Add(new DateSelectorScreen(game, closeSelector, abortSelector, DateTime.Now , DateSelectorType.YearsMouthsDays, title));
//game.Components.Add(new LoadingComponent(game, Color.Red, Color.Black * 0.8f));


namespace Services.Menu
{
    public abstract class OrientableScreen : DrawableGameComponent
    {
        protected DisplayOrientation prev_orientation;
        protected float press_wait;
        protected readonly float PRESS_INTERVAL = 0.5f;
        public OrientableScreen(Game game)
            : base(game)
        {
        }

        public override void Initialize()
        {
            base.Initialize();
            prev_orientation = GraphicsDevice.PresentationParameters.DisplayOrientation;
            ChangeOrientation();
        }

        protected virtual void ChangeOrientation()
        {
            prev_orientation = GraphicsDevice.PresentationParameters.DisplayOrientation;
            if (prev_orientation == DisplayOrientation.LandscapeLeft || prev_orientation == DisplayOrientation.LandscapeRight)
                SetLandScapeOrientation();
            else
                SetPortraitOrientation();
        }

        public abstract void SetPortraitOrientation();

        public abstract void SetLandScapeOrientation();

        public override void Update(GameTime gameTime)
        {
            if (press_wait < PRESS_INTERVAL)
                press_wait += (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (prev_orientation != GraphicsDevice.PresentationParameters.DisplayOrientation)
            {
                prev_orientation = GraphicsDevice.PresentationParameters.DisplayOrientation;
                ChangeOrientation();
            }
            base.Update(gameTime);
        }
        public bool RectContaintsVect(Rectangle r, Vector2 v)
        {
            return r.X <= v.X && r.Y <= v.Y && r.X + r.Width >= v.X && r.Y + r.Height >= v.Y;
        }
        public void OpenMarket()
        {
            try
            {
                MarketplaceDetailTask mkt = new MarketplaceDetailTask();
                mkt.Show();
            }
            catch { }
        }
        public void OpenMarket(string id)
        {
            try
            {
                MarketplaceDetailTask mkt = new MarketplaceDetailTask();
                mkt.ContentIdentifier = id;
                mkt.Show();
            }
            catch { }
        }
    }
}
